home *** CD-ROM | disk | FTP | other *** search
- Path: brighton.openmarket.com!decwrl!purdue!yuma!steffend
- From: steffend@lamar.colostate.edu (Dave Steffen)
- Newsgroups: comp.lang.c++
- Subject: Re: First C++ Program.......
- Date: 26 Jan 1996 01:32:15 GMT
- Organization: Colorado State University, Fort Collins, CO 80523
- Message-ID: <4e9auv$325i@yuma.ACNS.ColoState.EDU>
- References: <4e5qeu$7f0@server1.ctc.com>
- NNTP-Posting-Host: glitch.physics.colostate.edu
- X-Newsreader: TIN [version 1.2 PL2]
-
- Michael D. Aesoph (aesoph@ctc.com) wrote:
- > Dear Collective:
-
- > I an a C programmer that has recently been tasked to do some
- > programming in C++. Virtually all of my work involves data acquisition
- > of some kind and I normally use National Instrument's LabWindows/CVI as
- > my programming environment. In standard programming, things are
- > relatively simple... Configure data acquisition, acquire data, plot
- > data, analyze data, save data, etc. etc. Now, in C++, there's all this
- > talk about classes, objects, and other things. The project manager wants
- > a "sensor" class.... OK, where's the link??? I still have to do all of
- > the tasks mentioned before, but embedded apparently in a class????
- > Please advise.. I know that this is the classic stumbling block for
- > beginning C++ programmers, so don't make fun of me!!!!
-
- > Michael D. Aesoph
-
- OK, I'll take a swing at it...
-
- First off, is there a particular reason your boss is making
- you do this? I mean, maybe there's a real need to go OO for this -
- like, a complicated interface to your sensors and screwing up the
- parameters in a function call means the control rods get pulled out
- of the reactor - BOOM! Or is this just your boss jumping on the "OO
- Bandwagon" and making everyone write in C++ because it's trendy? Of
- course, either way you've got to do it (assuming you like your
- job). But in the first case, you need to do some real OO programming,
- while in the latter case, you just need to make it _look_ like you're
- doing OO, while really keeping things the way they are (because the
- way things are works just fine).
-
- Don't laugh - I've got a friend who's a (reasonably) highly
- paid C++ expert, he's been on more projects where C++ is a mistake
- than otherwise!
-
- OK, so assuming you're really going to do this and do it
- right... Everything goes into the class. Pointers to memory locations,
- sensor state variables, functions to read and change state variables,
- functions to read from the sensor, functions to initialize the
- sensor... everything.
-
- Your programs then look something like this:
-
-
- HallProbe Selector (port_7);
-
- /*
- HallProbe is a class you've defined somewhere to run
- magnetic sensors. This one is called "Selector" (measures the mag
- field in a selector or something) and is the one plugged into port
- 7.
- /*
-
- // or, alternatively
-
- Sensor Selector (HallProbe, port_7)
-
- /*
- Sensor is a generic sensor class, HallProbe is a value of some
- enumerated type - this tells Selector that it's a mag field probe, as
- opposed to a pressure sensor.
- */
-
-
- // Now initialize it, if the constructor didn't already
-
- Selector.Initialize (high_gain);
-
- // high_gain is some value that tells the sensor what sensitivity to
- // use
-
- if (Selector.Errorstate() == OK)
-
- /*
- Check state of Selector. OK is some constant defined to match some
- return value of the Selector::Errorstate() member function...
- */
-
-
- The nice thing about this is that you can treat your sensors
- in your code like they are in the real world - an independent chunk of
- equipment. If the interface to your sensors is really complicated and
- hard to use, "wrapping" this complicated interface in C++ classes can
- be a Godsend (I use the fortran LAPACK library all the time, and the
- function calls are unbelievably ugly... but my C++ code is beautiful).
- On the other hand, if the interface is relatively simple,
- going OO won't get you much unless you're doing something really
- complicated with your sensors.
-
- OK, does this make any sense? Let me know if it doesn't and
- I'll try again. ;-)
-
- /\
- \/
-
- Dave Steffen No, his mind is not for rent
- Dept. of Physics To any God or Government
- Colorado State University Always hopeful, yet discontent
- steffend@lamar.colostate edu He knows changes aren't permanent-
- But change is...
- "Speak softly...
- ... and carry a black belt!" -Neal Peart / RUSH
- -----------------------------------------------------------------------
-
-
-
-